package com.lwl.service.impl.scl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lwl.dao.scl.TSclVisitRecordMapper;
import com.lwl.entity.MyPage;
import com.lwl.entity.Tuser;
import com.lwl.entity.scl.TSclVisitRecord;
import com.lwl.entity.scl.VisitRecord;
import com.lwl.service.scl.TSclVisitRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * (TSclVisitRecord)表服务实现类
 *
 * @author makejava
 * @since 2022-11-02 22:56:34
 */
@Service
public class TSclVisitRecordServiceImpl implements TSclVisitRecordService {
   @Autowired
   private TSclVisitRecordMapper tSclVisitRecordMapper;

   @Override
   public Boolean checkRecordid(Integer recordid) {
      TSclVisitRecord tSclVisitRecord = new TSclVisitRecord();
      tSclVisitRecord.setRecordid(recordid);
      int i = tSclVisitRecordMapper.selectCount(tSclVisitRecord);
      return i>0?true:false;
   }

   @Override
   public Boolean addOrUpdateVisitRecord(TSclVisitRecord tSclVisitRecord, HttpSession session) {
      int i = -1;
      Tuser user = (Tuser) session.getAttribute("user");
      String username = user.getUsername();

      if (tSclVisitRecord.getId()==null){
         tSclVisitRecord.setCreateby(username);
         tSclVisitRecord.setCreatetime(new Date());
         System.out.println("将要加入到的回访记录内容tSclVisitRecord = " + tSclVisitRecord);
         i = tSclVisitRecordMapper.insert(tSclVisitRecord);
      }else {
         tSclVisitRecord.setUpdateby(username);
         tSclVisitRecord.setUpdatetime(new Date());
         System.out.println("将要修改的回访记录内容tSclVisitRecord = " + tSclVisitRecord);
         i = tSclVisitRecordMapper.updateByPrimaryKeySelective(tSclVisitRecord);
      }
      return i>0?true:false;
   }

   @Override
   public PageInfo queryAll(MyPage myPage, VisitRecord visitRecord) {
      PageHelper.startPage(myPage.getPage(),myPage.getLimit());
      List<VisitRecord> visitRecords = tSclVisitRecordMapper.queryAll(visitRecord);
      return new PageInfo(visitRecords);
   }
}
